package cn.ljy.mes.web.controller.backstage.mes.productionorderstep;


import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.annotation.LimitRequest;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.mes.model.MesProductionOrderStep;
import cn.ljy.mes.model.query.MesProductionOrderStepQuery;
import cn.ljy.mes.service.MesProductionOrderStepService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "后台生产订单步骤管理模块")
@RestController
@RequestMapping(value = "/backstage/mes/productionOrderStep")
public class MesProductionOrderStepController extends BaseBackstageController<MesProductionOrderStep, MesProductionOrderStepQuery,String> {

    @Autowired
    private MesProductionOrderStepService baseService;

    @Override
    protected String getAuthorityPrefix() {
        return "mes:productionOrderStep";// 定义模块权限前缀
    }


    @ApiOperation(value = "开始生产",notes = "从就绪状态变为开始生产状态")
    @PreAuthorize("hasAuthority('mes:productionOrderStep:operator')")
    @LimitRequest
    @PatchMapping("/inProgress/{orderStepId}")
    public ResponseData updateStepStatusToInProgress(@PathVariable String orderStepId) {
        baseService.updateStepStatusToInProgress(orderStepId);
        return ResponseData.success(null);
    }

    @ApiOperation(value = "审核生产步骤")
    @PreAuthorize("hasAuthority('mes:productionOrderStep:audit')")
    @LimitRequest
    @PatchMapping("/audit")
    public ResponseData auditProductionOrderStep(@RequestBody MesProductionOrderStep productionOrderStep) {
        baseService.auditStep(productionOrderStep.getId(), productionOrderStep.getAuditResult(), productionOrderStep.getAuditNote());
        return ResponseData.success(null);
    }
//    public ResponseData auditProductionOrderStep(String orderStepId, Boolean auditResult, String auditNote) {
//        baseService.auditStep(orderStepId, auditResult, auditNote);
//        return ResponseData.success(null);
//    }
//
//    @ApiOperation(value = "开始生产（将订单转为生产状态")
//    @PreAuthorize("hasAuthority('mes:productionOrder:manage')")
//    @LimitRequest
//    @ApiImplicitParam(name = "ids", value = "要删除的id集合", required = true,paramType = "query",example ="[11,12,13]")
//    @PatchMapping("/beginProduction")
//    public ResponseData beginProduction(@NotEmpty(message="请选择记录")@RequestBody String[] ids) {
//        return ResponseData.success(baseService.beginProduction(ids));
//    }
}